package com.gcsoftware.utils;

/**
 * Created by qs on 2018/2/5.
 */
public class GenerateIDs {
    public static final String ID_TYPE_ROLE_ID = "DS_R_";
    public static final String ID_TYPE_INTERF_ID = "DS_I_";
    public static final String ID_TYPE_IPARAM_ID = "DS_P_";
    public static final String ID_TYPE_DSITEM_ID = "DS_IT_";
    public static final String ID_TYPE_APP_IP_ID = "DS_IP_";
    public static final String ID_TYPE_COMPANY_ID = "DS_COM_";
    public static final String ID_TYPE_USER_ID = "DS_U_";
    public static final String ID_TYPE_USER_PWD_ID = "DS_UP_";
    public static final String ID_TYPE_LOG_ID = "DS_LOG_";
    public static final String ID_TYPE_VERIFY_ID = "DS_V_";

    private static int maxRoleId = 0;
    private static int maxInterfId = 0;
    private static int maxIparamId = 0;
    private static int maxAppIpId = 0;
    private static int maxDsItemId = 0;
    private static int maxCompanyId = 0;
    private static int maxUserId = 0;
    private static int maxUserPWDId = 0;
    private static int maxLogId = 0;
    private static int maxVerifyId = 0;


    public static int getMaxRoleId() {
        return maxRoleId;
    }

    public static int getMaxInterfId() {
        return maxInterfId;
    }

    public static int getMaxIparamId() {
        return maxIparamId;
    }

    public static int getMaxAppIpId() {
        return maxAppIpId;
    }

    public static int getMaxDsItemId() {
        return maxDsItemId;
    }

    public static int getMaxCompanyId() {
        return maxCompanyId;
    }

    public static int getMaxUserId() {
        return maxUserId;
    }

    public static int getMaxUserPWDId() {
        return maxUserPWDId;
    }

    public static int getMaxLogId() {
        return maxLogId;
    }

    public static int getMaxVerifyId() {
        return maxVerifyId;
    }

    public static void setMaxRoleId (int maxRoleId) {
        GenerateIDs.maxRoleId = maxRoleId;
    }

    public static void setMaxInterfId(int maxInterfId) {
        GenerateIDs.maxInterfId = maxInterfId;
    }

    public static void setMaxIparamId(int maxIparamId) {
        GenerateIDs.maxIparamId = maxIparamId;
    }

    public static void setMaxAppIpId(int maxAppIpId) {
        GenerateIDs.maxAppIpId = maxAppIpId;
    }

    public static void setMaxDsItemId(int maxDsItemId) {
        GenerateIDs.maxDsItemId = maxDsItemId;
    }

    public static void setMaxCompanyId(int maxCompanyId) {
        GenerateIDs.maxCompanyId = maxCompanyId;
    }

    public static void setMaxUserId(int maxUserId) {
        GenerateIDs.maxUserId = maxUserId;
    }

    public static void setMaxUserPWDId(int maxUserPWDId) {
        GenerateIDs.maxUserPWDId = maxUserPWDId;
    }

    public static void setMaxLogId(int maxLogId) {
        GenerateIDs.maxLogId = maxLogId;
    }

    public static void setMaxVerifyId(int maxVerifyId) {
        GenerateIDs.maxVerifyId = maxVerifyId;
    }

    public static String GenerateId(String idType){
        int maxId = 0;
        switch (idType) {
            case ID_TYPE_ROLE_ID:
                maxRoleId ++;
                maxId = maxRoleId;
                break;
            case ID_TYPE_INTERF_ID:
                maxInterfId++;
                maxId = maxInterfId;
                break;
            case ID_TYPE_IPARAM_ID:
                maxIparamId ++;
                maxId = maxIparamId;
                break;
            case ID_TYPE_DSITEM_ID:
                maxDsItemId ++;
                maxId = maxDsItemId;
                break;
            case ID_TYPE_APP_IP_ID:
                maxAppIpId++ ;
                maxId = maxAppIpId;
                break;
            case ID_TYPE_COMPANY_ID:
                maxCompanyId ++;
                maxId = maxCompanyId;
                break;
            case ID_TYPE_USER_ID:
                maxUserId ++;
                maxId = maxUserId;
                break;
            case ID_TYPE_USER_PWD_ID:
                maxUserPWDId ++;
                maxId = maxUserPWDId;
                break;
            case ID_TYPE_LOG_ID:
                maxLogId ++;
                maxId = maxLogId;
                break;
            case ID_TYPE_VERIFY_ID:
                maxVerifyId ++;
                maxId = maxVerifyId;
                break;
        }
        return getIdFillZero(idType, maxId);
    }

    private static String getIdFillZero (String idType, int maxId) {
        int oLength = 32 - idType.length() - String.valueOf(maxId).length();
        return idType + String.format("%0" + oLength + "d", maxId);
    }

}
